<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__CSS__/x-admin.css" media="all">
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>组名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="desc" class="layui-form-label">
                介绍
            </label>
            <div class="layui-input-inline">
                <textarea class="layui-input" name="desc" id="desc"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit>
                增加
            </button>
        </div>
    </form>
</div>
<script src="__LIB__/layui/layui.js" charset="utf-8">
</script>
<script src="__JS__/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            name: function (value) {
                if (value.length < 3) {
                    return '组名最少3个字';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            $.post('{:url("admin.role/add")}', data.field, function (response) {
                layer.alert(response.msg, {icon: 6}, function (index) {
                    if (response.code == 0) {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    }
                    else {
                        layer.close(index);
                    }
                });

            });
            return false;
        });
    });
</script>
</body>

</html>